/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bd2_xml.persistencia;

import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author R3oLoN
 */
public class Selecionar {
    
    public static ResultSetMetaData getMetaData(String tabela) throws SQLException{        
        Connection conn = null;
        try {
            conn = Conexao.getConnection();
        } catch (IOException ex) {
            Logger.getLogger(Selecionar.class.getName()).log(Level.SEVERE, null, ex);
        }
        ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM "+tabela+";");
        conn.close();        
        return rs.getMetaData();
    }
    
    public static ResultSet getAllDate(String tabela) throws SQLException{
        Connection conn = null;
        try {
            conn = Conexao.getConnection();
        } catch (IOException ex) {
            Logger.getLogger(Selecionar.class.getName()).log(Level.SEVERE, null, ex);
        }
        return conn.createStatement().executeQuery("SELECT * FROM "+tabela+";");
    }
    
    public static boolean testeTabela(String tabela){
        Connection conn = null;
        boolean teste = false;
        try {
            conn = Conexao.getConnection();
        } catch (IOException ex) {
            Logger.getLogger(Selecionar.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            conn.createStatement().executeQuery("CREATE TABLE  "+tabela+"();");
            teste = true;
        } catch (SQLException ex) {            
            Logger.getLogger(Selecionar.class.getName()).log(Level.SEVERE, null, ex);            
        }
        return teste;
    }
}
